using System;
using System.Collections.Generic;
using System.Text;
using TVProgram.Base;
using System.Net;
using System.IO;
using System.Globalization;

namespace TVProgram.Channels
{
    class THVL : BaseChannel
    {
        public THVL(DateTime CurDay, string channel)
        {
            this._name = "THVL" + channel;
            this._date = CurDay;
            string Day = Convert.ToString(this._date.Day);
            if (Day.Length == 1)
                Day = "0" + Day;
            else
                Day = "" + Day;
            string Month = Convert.ToString(this._date.Month);
            if (Month.Length == 1)
                Month = "0" + Month;
            else
                Month = "" + Month;
            string Year = Convert.ToString(this._date.Year);
            this._url = "http://thvl.vn/?cat=40&kenh=THVL"+channel+"&ngay=" + Year + "-" + Month + "-" + Day;
        }

        public override void GetTextFromHtml(string html)
        {

            //string stra = "<td class=\"tdFormRow\" align=\"center\">";
            string str1 = "class=\"Image\" style=\"\" align=\"center\" valign=\"top\" width=\"15\"><b>";
            string str2 = "</b></td>";
            int curIndex = 0;

            while (true)
            {
                curIndex = html.IndexOf(str1, curIndex);
                if (curIndex == -1)
                    break;
                int startIndex = curIndex + str1.Length;

                curIndex = html.IndexOf(str2, startIndex);
                if (curIndex == -1)
                    break;
                int endIndex = curIndex;

                string StrTime = html.Substring(startIndex, endIndex - startIndex);
                string strHour = StrTime.Substring(0, 2);
                int Hour = Convert.ToInt32(strHour);
                if (Hour > 23)
                    break;
                curIndex += str2.Length;

                //string strb = "class=\"Image\" style=\"\" align=\"center\" valign=\"top\" width=\"15\"><b>";
                string str3 = "<font style=\"font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 11px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;\" color=\"#06175d\">";
                string str4 = "</font>";

                //curIndex = html.IndexOf(strb, curIndex);
                curIndex = html.IndexOf(str3, curIndex);
                if (curIndex == -1)
                    break;
                startIndex = curIndex + str3.Length;

                curIndex = html.IndexOf(str4, startIndex);
                if (curIndex == -1)
                    break;
                endIndex = curIndex;
                curIndex += str4.Length;
                string StrTitle = html.Substring(startIndex, endIndex - startIndex);

                ProgramItem item = new ProgramItem();
                item.StartTime = item.GetDateTimeFromString(StrTime);
                item.Content = StrTitle;
                this._items.Add(item);
            }

        }
    }
}
